A search algorithm allows you to find a specific item in a data structure. For the GCSE, this data structure is usually a list, but one can also use other data structures (such as trees).

For example, if you are building a social media platform, you might have some data represented a bit like this:

[ { user_id: 1, name: "Alice", file_locations: ["files/rocket.jpg", "files/solving_equations.mp4", ...] }, { user_id: 2, name: "Bob", video_locations: ["files/dog.mp4", "files/bear.png", ...] }, { user_id: 3, name: "Charlie", file_locations: ["files/one.png", "files/two.png", ...] }, ... ]

(where ... means "and so on")

Which is all very well, until we want to get a list of Alice's videos because one of their friends has submitted a request to the server (assuming that we have checked that they have Alice's permission!!!). Here it is easy to see that Alice is the first person in our list, and therefore the problem is trivial. However, this is not always the case! Imagine you have a million users, and you want to find "Quentin" – in this case we have no idea where in the list Quentin is!

This is what a search algorithm is for – we might want to find the position of an item in a list (which is the, slightly boring, example that most textbooks give), or (much more frequently) we might want to find an item in our records based on a "key" (e.g. the name of the person).

There are a few search algorithms you should know about: